#include <bits/stdc++.h>

using namespace std;

long long tc = 1, n, ans, a[114514], pre[114514];
long long dp[114514][2][2][2];

void init() {
    ans = 0;
    scanf("%lld", &n);
    for (long long i = 1; i <= n; i++) {
        for (long long j = 0; j <= 1; j++) {
            for (long long k = 0; k <= 1; k++) {
                for (long long l = 0; l <= 1; l++) {
                    dp[i][j][k][l] = 0;
                }
            }
        }
    }
}

void slv() {
    for (long long i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        pre[i] = pre[i - 1];
        if (a[i] == a[i - 1]) {
            pre[i] += a[i];
        }
    }
    for (long long i = 1; i <= n; i++) {
        for (long long f = 0; f <= 1; f++) {
            for (long long j = 1; j < i; j++) {
                long long ff = (a[i] == a[j]);
                long long fff = (i == j + 1);
                if (fff) {
                    long long res = max(dp[j][f][0][0], dp[j][f][0][1]);
                    res = max(res, max(dp[j][f][1][0], dp[j][f][1][1]));
                    if (ff) {
                        res += a[i];
                    }
                    dp[i][f][ff][fff] = max(dp[i][f][ff][fff], res);
                    continue;
                }
                long long res = max(dp[j + 1][0][!f][0], dp[j + 1][1][!f][0]);
                if (ff) {
                    res += a[i];
                }
                res += pre[i - 1] - pre[j + 1];
                dp[i][f][ff][fff] = max(dp[i][f][ff][fff], res);
            }
        }
    }
    for (long long i = 0; i <= 1; i++) {
        for (long long j = 0; j <= 1; j++) {
            for (long long k = 0; k <= 1; k++) {
                ans = max(ans, dp[n][i][j][k]);
            }
        }
    }
    printf("%lld\n", ans);
}

int main() {

    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    scanf("%lld", &tc);
    while (tc--) {
        init();
        slv();
    }

    return 0;
}
